# include <iostream>
# include <cstdio>
const int maxn = 505;
const int maxp = 505;
int a[maxn],b[maxn];
int ans[maxp];
int T;
int N, P;
int main()
{
    freopen("B-large.in", "r", stdin);
    freopen("b-large.txt", "w", stdout);
    std::cin >> T;
    for (int ica = 1; ica <= T; ++ica) {
        std::cin >> N;
        for (int i = 1; i <= N; ++i) std::cin >> a[i] >> b[i];
        std::cin >> P;
        std::cout << "Case #" << ica << ":";
        for (int i = 1, x; i <= P; ++i) {
            std::cin >> x;
            int cnt = 0;
            for (int j = 1; j <= N; ++j) {
                if (a[j]<=x&&x<=b[j]) {
                    ++cnt;
                }
            }
            std::cout << " " << cnt;
        }
        std::cout << std::endl;
    }
    return 0;
}
